/* Copyright (C) 2010 Fredrique Samuels, fredriquesamuels@gmail.com */

/*
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/


#ifndef TEST_ANIMATION_H_
#define TEST_ANIMATION_H_

#include "testcase.h"
#include "../src/animate.h"
#include "../src/utils.h"

class test_animation:public testcase
{
public:
	test_animation():testcase() {};
virtual ~test_animation() {
}
;

inline virtual void run_tests() {
	cout<<"\n*********************************"<<endl;
	cout<<"*"<<endl;
	cout<<"* Running Animation Tests"<<endl;
	cout<<"*"<<endl;
	cout<<"*********************************"<<endl;
	testLinearAnimate();
	testAniVar();
	testAniVector();
}

inline void testAniVar() {
	tri::anivar var;
	
	cout<<"testing default value....."<<endl;
	assert(var.getValue()==0);
	
	
	cout<<"testing set/get....."<<endl;
	var.setValue(10.0);
	assert(var.getValue()==10.0);
	
	cout<<"testing animation linear....."<<endl;
	var.setValue(0.0);
	var.setTargetValue(10.0);
	tri::utils::sleep(600);
	float v = var.getValue();
	assert(v > 5);
	
	tri::utils::sleep(600);
	assert(var.getValue() == 10.0);
	
	var.setValue(10.0);
	var.setTargetValue(-10.0,2.5);
	tri::utils::sleep(600);
	assert(var.getValue() > 5.0);
	
	tri::utils::sleep(1000);
	assert(var.getValue() < 0.0);
	
	tri::utils::sleep(1000);
	assert(var.getValue() == -10.0);
	
}

inline void testLinearAnimate() {
	tri::anivar var;
	
	cout<<"testing linear animate....."<<endl;
	float start = 0;
	float end = 10;
	float cur_val = -1;
	tri::utils::timer _timer;
	_timer.setMode(TIMER_MODE);
	
	_timer.start();
	
	tri::utils::sleep(600);
	
	cur_val = tri::animate_linear(start,end,_timer,cur_val);
	assert(cur_val > 5.0);
	
	tri::utils::sleep(600);
	cur_val = tri::animate_linear(start,end,_timer,cur_val);
	assert(cur_val == 10.0);
	
	start = 20.0;
	end = 50.0;
	
	cur_val = -1;
	_timer.reset();
	
	tri::utils::sleep(600);
	cur_val = tri::animate_linear(start,end,_timer,cur_val);
	assert(cur_val > 35.0);
	
	tri::utils::sleep(600);
	cur_val = tri::animate_linear(start,end,_timer,cur_val);
	assert(cur_val == 50.0);
	
}

void testAniVector(){
	tri::anivector v1;
	
	cout<<"testing anivector constructors....."<<endl;
	
	float value[3];
	v1.getValue(value);
	assert(v1.getX()==0.0);
	assert(v1.getY()==0.0);
	assert(v1.getZ()==0.0);
	
	assert(value[0] == 0.0);
	assert(value[1] == 0.0);
	assert(value[2] == 0.0);
	
	
	tri::anivector v2(1.0,2.0,3.0);
	
	v2.getValue(value);
	assert(v2.getX()==1.0);
	assert(v2.getY()==2.0);
	assert(v2.getZ()==3.0);
	
	assert(value[0] == 1.0);
	assert(value[1] == 2.0);
	assert(value[2] == 3.0);
	
	tri::anivector v3(value);
	
	v3.getValue(value);
	assert(v3.getX()==1.0);
	assert(v3.getY()==2.0);
	assert(v3.getZ()==3.0);
	
	assert(value[0] == 1.0);
	assert(value[1] == 2.0);
	assert(value[2] == 3.0);
	
	
	cout<<"testing anivector animation....."<<endl;
	
	v3.setValue(0,0,0);
	v3.setTargetValue(10,10,10);
	
	tri::utils::sleep(600);
	v3.getValue(value);
	assert(value[0] > 5.0 && value[0] < 10.0);
	assert(value[1] > 5.0 && value[1] < 10.0);
	assert(value[2] > 5.0 && value[2] < 10.0);
	
	
	tri::utils::sleep(600);
	v3.getValue(value);
	assert(value[0] == 10.0);
	assert(value[1] == 10.0);
	assert(value[2] == 10.0);
}

};

#endif /*TEST_ANIMATION_H_*/
